package study.lxy.spring.springboot2.mq.sender;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import study.lxy.spring.springboot2.entity.LoginUser;
import study.lxy.spring.springboot2.mq.receiver.LoginLogReceiver;
import study.lxy.spring.springboot2.utils.JsonUtils;

@Component
public class LoginSender {
    private static final Logger logger = LoggerFactory.getLogger(LoginSender.class);
    //@Autowired
    //private RabbitTemplate template;
    @Autowired
    private AmqpTemplate rabbitTemplate;

    public void sendLoginLog(LoginUser user){
        logger.info("send message : {}",JsonUtils.toJsonString(user));
        rabbitTemplate.convertAndSend("login.log", JsonUtils.toJsonString(user));
    }

}
